{extend name="public/base" /}
{block name="style"}
<style>
    /* 地址列表容器 */
    .address-list {
        margin-top: 10px;
    }

    /* 地址项样式 */
    .address-item {
        background-color: white;
        padding: 15px;
        margin-bottom: 10px;
        border-radius: 8px;
        position: relative;
        box-shadow: 0 1px 3px rgba(0,0,0,0.05);
        animation: fadeIn 0.3s ease;
    }

    @keyframes fadeIn {
        from { opacity: 0; transform: translateY(-10px); }
        to { opacity: 1; transform: translateY(0); }
    }

    .address-header {
        display: flex;
        justify-content: space-between;
        margin-bottom: 8px;
    }

    .address-name {
        font-size: 16px;
        color: #333;
        font-weight: 500;
    }

    .address-tag {
        display: inline-block;
        padding: 2px 8px;
        font-size: 12px;
        color: white;
        background-color: #1AAD19;
        border-radius: 4px;
    }

    .address-detail {
        font-size: 14px;
        color: #666;
        line-height: 1.5;
        margin: 10px 0;
        word-break: break-all; /* 比特币地址过长时自动换行 */
        padding: 8px;
        background-color: #f5f5f5;
        border-radius: 4px;
        position: relative;
    }

    .copy-btn {
        position: absolute;
        right: 8px;
        top: 50%;
        transform: translateY(-50%);
        color: #1AAD19;
        font-size: 12px;
        cursor: pointer;
        display: flex;
        align-items: center;
        gap: 4px;
    }

    .address-footer {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .address-actions {
        display: flex;
        gap: 15px;
    }

    .address-action {
        color: #888;
        font-size: 14px;
        cursor: pointer;
    }

    .address-action.edit {
        color: #1AAD19;
    }

    .address-action.delete {
        color: #E64340;
    }

    /* 新增地址按钮 */
    .add-address-btn {
        position: fixed;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        width: calc(100% - 30px);
        padding: 13px 0;
        background-color: #1AAD19;
        color: white;
        border: none;
        border-radius: 5px;
        font-size: 16px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        cursor: pointer;
        box-shadow: 0 2px 10px rgba(26, 173, 25, 0.3);
        transition: all 0.2s;
    }

    .add-address-btn:active {
        background-color: #179c16;
        transform: translateX(-50%) scale(0.98);
    }

    /* 空状态样式 */
    .empty-address {
        padding: 80px 20px;
        text-align: center;
        color: #999;
    }

    .empty-icon {
        font-size: 60px;
        color: #ddd;
        margin-bottom: 20px;
    }

    .empty-text {
        font-size: 16px;
        margin-bottom: 30px;
    }
</style>

{/block}
<!--主体-->
{block name="content"}
<div class="header">
    <a href="javascript:void(0);" class="back-btn">
        <i class="fa fa-angle-left" style="font-size: 24px;"></i>
    </a>
    <h1 class="header-title">设置提现地址</h1>
</div>
<div class='weui-content'>
    <div class="address-list" id="addressList">
        <!-- 地址项1 - 默认地址 -->
        {foreach name="list" item="vo"}
            <div class="address-item">
                <div class="address-header">
                    <div class="address-name">{$vo.name}</div>
                    {if $vo.is_default==1}
                        <div class="address-tag">默认地址</div>
                    {/if}
                </div>
                <div class="address-detail">
                    {$vo.address}
                    <span class="copy-btn" data-address="{$vo.address}">
                    <i class="fa fa-copy"></i> 复制
                </span>
                </div>
                <div class="address-footer">
                    {if $vo.is_default==0}
                        <div class="address-action set-default"  onclick='setDefault("{$vo.id}")'>设为默认</div>
                    {/if}
                    <div class="address-actions">
                        <div class="address-action edit"    onclick='edit("{$vo.id}")'>编辑</div>
                        <div class="address-action delete"  onclick='del("{$vo.id}")'>删除</div>
                    </div>
                </div>
            </div>
        {/foreach}

    </div>

    <!-- 空状态 (默认隐藏) -->
    {empty name="list"}
        <div class="empty-address" id="emptyAddress">
            <div class="empty-icon">
                <i class="fa fa-link"></i>
            </div>
            <div class="empty-text">您还没有保存比特币地址</div>
            <a href="/address-add.html" class="add-address-btn" id="emptyAddBtn">
                <i class="fa fa-plus"></i> 新增地址
            </a>
        </div>
    {else/}
        <!-- 新增地址按钮 -->
        <a href="/address-add.html" class="add-address-btn" id="addAddressBtn">
            <i class="fa fa-plus"></i> 新增地址
        </a>
    {/empty}
</div>

{/block}
{block name="script"}
<script>

        // 复制地址功能
        $('.copy-btn').click(function() {
            const address = $(this).prev("span").data('address');
            // 创建临时文本区域用于复制
            const tempInput = $('<input>').val(address).appendTo('body');
            tempInput.select();
            document.execCommand('copy');
            tempInput.remove();
            $.toast("复制成功");
        });
        function del(id) {
            $.showLoading('设置中');
            $.post("/address-delete.html", {id:id}, function (res) {
                $.hideLoading();
                if (res.code == 0) {
                    $.toast(res.msg, function () {
                        window.location.href = "/address-list.html"
                    })
                } else {
                    $.toptip(res.msg, 'error');
                    return;
                }
            }, 'json')
        }
        function edit(id) {
            window.location.href="/address-edit/"+id;
        }
        function setDefault(id) {
            $.showLoading('设置中');
            $.post("/address-set-default.html", {id:id}, function (res) {
                $.hideLoading();
                if (res.code == 0) {
                    $.toast(res.msg, function () {
                        window.location.href = "/address-list.html"
                    })
                } else {
                    $.toptip(res.msg, 'error');
                    return;
                }
            }, 'json')
        }

</script>
{/block}
